/*
SIUM Master Dofile

Author: GA
*/

//set up globals
global dir "C:\Users\Garrett\Documents\Grad_School\Papers\SIUM_JPE\Replication" //master directory. Changing this should be all you need to do.

global data "$dir/Data"
global temp "$dir/Temp"
global dofiles "$dir/Dofiles"
global output "$dir/Output"
global model "$dir/Model"

******STEP 1: RUN FIRST SET OF DOFILES TO PREPARE TARGET MOMENTS AND CREATE A FEW MOTIVATING FIGURES

//simple figures, motivation, and data prep work
do "$dofiles/01_simple_figures.do"
do "$dofiles/02_cz_motivation.do"
do "$dofiles/03_prep_psid.do"
do "$dofiles/04_clean_psid.do"
do "$dofiles/05_prep_census.do"

//collecting state-level attributes to feed to the model
do "$dofiles/06a_state_skill_prices.do"
do "$dofiles/06b_state_cp_census.do"
do "$dofiles/06c_state_cp_acs.do"
do "$dofiles/06d_state_model_attributes.do"
do "$dofiles/06e_state_tuition_costs.do"
do "$dofiles/06f_taxes_readin.do"
do "$dofiles/06g_prepare_proximity_matrix.do"
do "$dofiles/06h_prepare_cfact_data.do"
do "$dofiles/06i_prepare_amenities.do"

//late-stage HC shock and financial aid schedule
do "$dofiles/07_estimate_late_shocks.do" //gets mean, variance of period 3-4 HC shocks
do "$dofiles/07_grants_npsas.do"

//form parent initial conditions and realization probabilities of fertility and marriage
do "$dofiles/08a_marriage_probs_kids.do"
do "$dofiles/08b_parent_distribution.do"
do "$dofiles/08e_parent_dist_p25.do" 
//do "$dofiles/08c_marriage_probs_parents_p25.do"
do "$dofiles/08d_fertility_probs.do"

do "$dofiles/08f_marriage_prob_kid_types.do"
do "$dofiles/08g_prepare_decomp_data.do" //for decomposition exercise later

//form target moments and bootstraps
do "$dofiles/09a_targ_moments_earnings.do"
do "$dofiles/09a_targ_moments_earnings_boot.do"
do "$dofiles/09a2_targ_moments_earnings" //modified HVY version

//some issues to resolve here. Then we should be golden
do "$dofiles/09b_targ_moments_migration.do"  
do "$dofiles/09b_targ_moments_migration_boot.do"
do "$dofiles/09c_cds_time.do"
do "$dofiles/09c_cds_time_boot.do"
do "$dofiles/09d_iim_moments.do"
do "$dofiles/09d_iim_moments_state.do"
do "$dofiles/09e_nlsy_moment_prep.do"
do "$dofiles/09f_psid_migration_dynamic.do"
do "$dofiles/09f_psid_migration_dynamic_boot.do"
do "$dofiles/09g_moments_race_coll_mig.do"
exit
*******STEP 2: OPEN SIUM_MASTER.JL AND REPLICATE THE PARTS OF THE MODEL YOU WOULD LIKE TO


*******STEP 3: RUN THE REMAINING DOFILES THAT EVALUATE VARIOUS COUNTERFACTUALS AND ROBUSTNESS CHECKS
//model fit
do "$dofiles/10_model_fit.do"
do "$dofiles/10b_mig_corr_overall.do"

//counterfactual analysis
do "$dofiles/11a_cfact_analysis_main.do"
do "$dofiles/11a_cfact_analysis_main_amen.do"
do "$dofiles/11a_cfact_analysis_main_statcheck.do"
do "$dofiles/11b_cfact_analysis_shock.do"
do "$dofiles/11c_cfact_retention.do"
do "$dofiles/11d_cfact_school.do"
do "$dofiles/11e_var_decomp.do"

//behavior of objective function, additional robustness checks
do "$dofiles/12_identification_test_plots.do"
do "$dofiles/app_dahl_hs_premium_2000.do"
do "$dofiles/app_dahl_hs_premium_2010.do"
do "$dofiles/app_psid_skill_prices.do"
do "$dofiles/app_state_skill_prices_exp_bpl.do"
do "$dofiles/app_state_skill_prices_kw.do"
do "$dofiles/10_movecost_analysis"

*******STEP 4: CLEAN OUT THE TEMP DIRECTORY
cap ssc install filelist
cd "$dir/Temp/boot"
filelist
levelsof filename, clean local(files)
foreach file in `files'{
	erase "$dir/Temp/boot/`file'"
}

cd "$dir/Temp"
filelist
levelsof filename, clean local(files)
foreach file in `files'{
	cap erase "$dir/Temp/`file'"
}
